import java.util.Stack;
public class Solution {
    public boolean IsPopOrder(int [] pushA, int [] popA) {
        Stack<Integer> stack = new Stack<>();
        int popNum = 0;
        for (int i = 0; i < popA.length; i++) {
            stack.push(pushA[i]);
            //一直比较栈顶元素，直到比完
            while (!stack.empty() && stack.peek() == popA[popNum]) {
                stack.pop();
                popNum++;
            }
        }
        //若有剩下的元素，就证明没匹配上
        return stack.empty();
    }
}